<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['op']=='list'){
	//搜索
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$fields=array('id','title','img','des');
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$total='';
	$parameter=array(
		'params'=>$params,
		'fields'=>$fields,
		'limit'=>array($pindex,$psize),
	);
	$list=pdo_getslice('core_account_product_fenlei',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'产品分类列表'),
			'1'=>array('op'=>'edit','title'=>'添加产品分类'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'img','title'=>'分类图标','type'=>'image'),
			array('name'=>'title','title'=>'分类标题','type'=>'string'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$return['htmls']=$htmls;
	exi($return);
}

if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('core_account_product_fenlei',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'分类',
		'tabs'=>array(
			'0'=>array('op'=>'list','title'=>'产品分类列表'),
			'1'=>array('op'=>'edit','title'=>'添加产品分类'),
		),
		'edit'=>array(
			'0'=>array('type'=>'string','title'=>'标题','name'=>'title', 'help'=>'' ),
			'1'=>array('type'=>'string','title'=>'描述','name'=>'des', 'help'=>'' ),
			'2'=>array('type'=>'image','title'=>'图标','name'=>'img', 'help'=>'' ),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'des'=>trim($postdata['des']),
		'img'=>trim($postdata['img'])
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('core_account_product_fenlei',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('产品分类修改成功！');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('core_account_product_fenlei',$data);
		exi('产品分类增加成功！');
	}
}

if($_RQ['op'] == 'del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_account_product_fenlei',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_account_product_fenlei',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
			}
		}
	}
	exi('删除成功！');
}

?>